﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace LogFileConnector
{
    class Configuration
    {
        /// <summary>
        /// 
        /// </summary>
        public static string destination = "C:\\destfile.txt";
        public static string source = "C:\\";
        public static bool writeLog = true;
        public static string logOutputDestination = "file";
        public static string fileExtension = "csv";
        public static string validLogStartsWith = "DATUM;UHRZEIT";
        public static Encoding destinationEncoding = Encoding.Default;
        public static bool destinationAppend = true;
        public static bool outputProcessInformation = true;
        public static bool showLogFileErrors = true;
        public static bool deleteSourceFiles = false;
        public static bool searchSourceRecursive;

        /// <summary>
        /// 
        /// </summary>
        public static void readConfig() 
        {
            StreamReader reader = new StreamReader("config.xml");
            System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(typeof(config));
            config c = (config)ser.Deserialize(reader);
            reader.Close();
            destination = c.destination;
            source = c.source;
            writeLog = c.writeLog;
            logOutputDestination = c.logOutputDestination;
            fileExtension = c.fileExtension;
            validLogStartsWith = c.validLogStartsWith;
            destinationAppend = c.destinationAppend;
            outputProcessInformation = c.outputProcessInformation;
            showLogFileErrors = c.showLogFileErrors;
            deleteSourceFiles = c.deleteSourceFiles;
            searchSourceRecursive = c.searchSourceRecursive;

            switch (c.destinationEncoding) 
            {
                case ("ASCII"):destinationEncoding = Encoding.ASCII;break;
                case ("UNICODE"): destinationEncoding = Encoding.Unicode; break;
                case ("UTF-8"): destinationEncoding = Encoding.UTF8; break;
                case ("UTF-7"): destinationEncoding = Encoding.UTF7; break;
                case ("UTF-32"): destinationEncoding = Encoding.UTF32; break;
                case ("BIGENDIANUNICODE"): destinationEncoding = Encoding.BigEndianUnicode; break;
                default: destinationEncoding = Encoding.Default;break;
            }
        }
    }
}
